<template>
  <div>
    <Header></Header>
    <Swiper :list="SwiperList"></Swiper>
    <Icons :list="Iconlist"></Icons>
    <Recommand :list="RecommendList"></Recommand>
    <Weekand :list="WeekandList"></Weekand>
  </div>
</template> 
<script>
import Header from "./components/Header.vue";
import Swiper from "./components/Swiper.vue";
import Icons from "./components/Icons.vue";
import Recommand from "./components/recommand";
import Weekand from "./components/Weekand.vue";
import axios from "axios";
import { mapState } from "vuex";
export default {
  mounted() {
    this.lastCity = this.city;
    this.getData();
  },
  activated() {
    // 第一次的城市如果不等于第二次从另一个页面传过来的城市 则将新传过来的城市赋值到当前页面 避免重新加载时加载错误
    if (this.lastCity !== this.city) {
      this.lastCity = this.city;
      this.getData();
    }
  },
  computed: {
    ...mapState(["city"])
  },
  name: "Home",
  components: {
    Header,
    Swiper,
    Icons,
    Recommand,
    Weekand
  },
  data() {
    return {
      SwiperList: [],
      Iconlist: [],
      WeekandList: [],
      RecommendList: [],
      lastCity: ""
    };
  },
  methods: {
    getData() {
      axios.get("/api/index.json?city=" + this.city).then(this.getDatasucc);
    },
    getDatasucc(res) {
      if (res.data.ret === true) {
        // console.log(res.data.data);
        this.SwiperList = res.data.data.swiperList;
        this.Iconlist = res.data.data.iconList;
        this.WeekandList = res.data.data.weekendList;
        this.RecommendList = res.data.data.recommendList;
        // console.log(this.Iconlist)
      }
    }
  }
};
</script>
<style lang="" >
</style>
